#pragma once
#include "Course.h"
#include "Result.h"
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

class Student
{
private:
	//Betyg 3
	//Uppgift 3.1
	string firstName;
	string secondName;
	int enrollmentYear;
	int id;

public:
	vector<Course> Courses;
	vector<Course>::iterator CI;


public:


	// Uppgift 3.1
	Student() 
	{
		firstName = " ";
		secondName = " ";
		enrollmentYear = 0;
		id = -1;
	}

	Student(int id,string firstName, string secondName, int enrollmentYear)
	{
		this->id = id;
		this->firstName = firstName;
		this->secondName = secondName;
		this->enrollmentYear = enrollmentYear;
	}

	friend bool operator==(const Student s1, const Student s2)
	{
		return s1.GetId() == s2.GetId();
	}




	string GetfirstName() { return this->firstName; }
	void SetfirstName(string firstName){ this->firstName = firstName; }

	string GetsecondName() { return this->secondName; }
	void SetsecondName(string secondName) { this->secondName = secondName; }

	int GetenrollmentYear() { return this->enrollmentYear; }
	void SetenrollmentYear(int enrollmentYear) { this->enrollmentYear = enrollmentYear; }

	int GetId() const { return this->id; }
	void SetId(int id) { this->id = id; }

	//Uppgift 3.2
	void Read()
	{
		cout << "Firstname: ";
		getline(cin, firstName);
		cout << "Secondname: ";
		getline(cin, secondName);
		cout << "Enrollmentyear: ";
		cin >> enrollmentYear;
		cout << "Id: ";
		cin >> id;
		cout << endl;
	}

	void Write()
	{
		cout << "Id: " << id << endl;
		cout << "Firstname: " << firstName << endl;
		cout << "Secondname: " << secondName << endl;
		cout << "Enrollmentyear: " << enrollmentYear << endl;
	}

	//Uppgift 3.3

	friend ostream& operator<<(ostream &o, const Student &Student)
	{
		o << "(";
		o << Student.id << ",";
		o << Student.firstName << ",";
		o << Student.secondName << ",";
		o << Student.enrollmentYear;
		o << ")";
		return o;
	}

	friend istream& operator>>(istream &i, Student& Student)
	{
		string s;
		getline(i, s, '(');
		getline(i, s, ',');
		istringstream iss(s);
		iss >> Student.id;
		getline(i, Student.firstName, ',');
		getline(i, Student.secondName, ',');
		getline(i, s, ')');
		istringstream iss2(s);
		iss2 >> Student.enrollmentYear;
		return i;
	}


	//Betyg 4

	void AddCourse(Course c)
	{
		Courses.push_back(c);
	}

	void SearchForCoursesAndAddResult(int courseid)
	{
		Course tempcourse;
		tempcourse.SetId(courseid);

		auto CI = find(Courses.begin(), Courses.end(), tempcourse);

		if (CI != Courses.end())
		{
			int testid;
			cout << "TestID: ";
			cin >> testid;

			int points;
			cout << "Points: ";
			cin >> points;
			Result tempresult(testid, points);

			CI->AddResult(tempresult);
		}
	}




	string PrintCourse(int j)
	{
		ostringstream oss;
		oss << "(" << Courses[j].GetName() << "," << Courses[j].GetId() << ")" << endl;
		return oss.str();
	}



	~Student();
};
